//
//  AIncomeProgressCell.m
//  DistributorAB
//
//  Created by 主事丫环 on 2019/8/21.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "AIncomeProgressCell.h"

@implementation AIncomeProgressCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

// 1. 初始化子视图
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // 头像
        UIImageView *headImageView = [[UIImageView alloc] init];
        headImageView.frame = CGRectMake(21, 10, 33, 40);
        [self.contentView addSubview:headImageView];
        self.headImageView = headImageView;
        
        // 区域名称
        UILabel *areanameLabel = [[UILabel alloc] init];
        areanameLabel.frame = CGRectMake(headImageView.right + 16, 10, 90, 17);
        areanameLabel.font = FontSize(15);
        [self.contentView addSubview:areanameLabel];
        self.areanameLabel = areanameLabel;
        
        // 进度条
        UILabel *progressLab = [[UILabel alloc] init];
        progressLab.frame = CGRectMake(headImageView.right + 16, areanameLabel.bottom + 7, KWIDTH - 160, 17);
        progressLab.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        [self.contentView addSubview:progressLab];
        self.progressLab = progressLab;
        
        _greenProgressLab = [[UILabel alloc] init];
        _greenProgressLab.frame = CGRectMake(self.headImageView.right + 16,  self.areanameLabel.bottom + 7, 0, 0);
        _greenProgressLab.backgroundColor = [UIColor colorWithHexString:@"#70BE68"];
        [self.contentView addSubview:_greenProgressLab];

        
        // 金额
        UILabel *AmountLabel = [[UILabel alloc] init];
        AmountLabel.frame = CGRectMake(self.progressLab.right+6, areanameLabel.bottom + 7, 60, 17);
        AmountLabel.numberOfLines = 0;
        AmountLabel.font = FontSize(14);
        AmountLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:AmountLabel];
        self.AmountLabel = AmountLabel;
        
        // 箭头
        UIImageView *arrowImg = [[UIImageView alloc] init];
        arrowImg.frame = CGRectMake(AmountLabel.right+6, 32, 10, 13);
        [self.contentView addSubview:arrowImg];
        self.arrowImg = arrowImg;
    }
    
    return self;
}

-(void)setModel:(DISAProfitList *)model
{
    _model = model;
    if (_model) {
        
        if ( [model.earning floatValue]>0 && [self.AkkEar floatValue]>0) {
            
            _greenProgressLab.frame = CGRectMake(self.headImageView.right + 16,  self.areanameLabel.bottom + 7, (KWIDTH - 160) * ([model.earning floatValue]/[self.AkkEar floatValue]), 17);

        }
        else if ( [model.earning floatValue] == 0 || [self.AkkEar floatValue] == 0 )
        {
             _greenProgressLab.frame = CGRectMake(self.headImageView.right + 16,  self.areanameLabel.bottom + 7, 0, 17);
        }
        
    }
}
@end
